import { Bus, CoinPairs as CoinPairS } from "@/connetion/Bus";
import i18n from "@/locals";
import { ref, toRaw } from "vue";
interface Btn {
    name: string;
    val: string;
    cols: number;
    key: TriangleType;
}
enum TriangleType {
    NONE,
    UP,
    DOWN
}
interface CoinPairs {
    id: number;
    symbol: string;
    show?: any;
    priceDisplayDp: number;
    sizeDisplayDp: number;
    sort: number;
    imageUrl: string;
    erc?: any;
    pairCreated?: any;
    tokenAmount?: any;
    tokenAddress: string;
    pairContractAddress: string;
    intervals: Interval[];
    priceChangePercent: number;
    lastPrice: number;
    quoteVolume: number;
    baseCurrency: string;
    quoteCurrency: string;
}

interface Interval {
    type: number;
    name: string;
    description: string;
}

const btns = ref<Btn[]>([
    { name: i18n.global.t("message.TableF.a"), val: "id", cols: 4, key: TriangleType.NONE },
    { name: i18n.global.t("message.TableF.b"), val: "lastPrice", cols: 3, key: TriangleType.NONE },
    { name: i18n.global.t("message.TableF.c"), val: "priceChangePercent", cols: 3, key: TriangleType.NONE },
    { name: i18n.global.t("message.TableF.d"), val: "quoteVolume", cols: 2, key: TriangleType.NONE }
]);

const listArr = ref<CoinPairs[]>([]);
const btnKey = ref(btns.value[0]);

function keyDown(btn: Btn) {
    switch (btn.key) {
        case TriangleType.NONE:
            btn.key = TriangleType.UP;
            break;
        case TriangleType.UP:
            btn.key = TriangleType.DOWN;
            break;
        case TriangleType.DOWN:
            btn.key = TriangleType.NONE;
            break;
    }
    btns.value.forEach(item => {
        //充值所有没选中设置为NONE
        if (item.val !== btn.val) {
            item.key = TriangleType.NONE;
        } else {
            Bus.emit(CoinPairS, toRaw(item));
        }
    });
}

function resetKey() {
    btns.value.forEach(item => (item.key = TriangleType.NONE));
}

export { listArr, btns, btnKey, keyDown, resetKey, TriangleType };
export type { CoinPairs };
